home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 19 / CU Amiga Magazine's Super CD-ROM 19 (1998)(EMAP Images)(GB)[!][issue 1998-02].iso / CUCD / Readers / Gui4Cli / Tools / Calc.gc next >
Text File  |  1997-12-02  |  7KB  |  290 lines

  1. G4C
  2.  
  3. ; calc.gc
  4.  
  5. ; A calculator, which uses ARexx to calculate & display the results.
  6. ; NOTE : ** means "to the power of"  i.e. 5**2 = 25
  7.  
  8. ; Other ARexx operators can be entered manually if needed.
  9.  
  10.  
  11. WINBIG   400 24 160 128 "RexxCalc"   ; Our window.
  12. WinType  11110001                ; It has all standard gadgets & bottom resize
  13. WINBACKGROUND PATTERN 0 2        ; Add a flashy background..
  14. varpath ''             ; use only private variables
  15.  
  16. BOX  0 0 0 0 IN ICONDROP ; A window sized box, taking us way beyond mere "cool"
  17.  
  18. ;************************** GENERAL EVENTS ***********************************
  19.  
  20. xONLOAD                     ; Upon loading of the GUI
  21. ifexists port AREXX         ; check for rexxmast
  22.    ;
  23. elseifexists file rexxmast
  24.    run rexxmast
  25. elseifexists file sys:system/rexxmast
  26.    run sys:system/rexxmast
  27. else
  28.    ezreq "Could not find RexxMast" Abort ''
  29.    guiquit calc.gc
  30.    stop
  31. endif
  32. setscreen calc.gc $*SCREEN
  33. calc.var = ""               ; This is our main variable
  34. setgad calc.gc 2 HIDE      ; hide the ticker tape
  35. GUIOPEN calc.gc
  36. setvar mem  .mem1           ; These are the Memory variables
  37. setvar .mem1 0              ;     The ones starting with a full stop,
  38. setvar .mem2 0              ;     are env: variables
  39. setvar .mem3 0
  40. setvar .mem4 0
  41. setvar .mem5 0
  42. setvar membuff ""
  43. setvar .result "0"          ; somewhere to put the result (env: variable)
  44. setvar calcmode SMALL       ; small/big window
  45.  
  46. xonclose
  47. guiquit calc.gc
  48.  
  49. xOnQuit                     ; On quitting we delete the env variables, 
  50. delete env:.mem#?           ; so they don't linger in Env:
  51. delvar .result
  52.  
  53. ;***************************** BUTTONS GALORE ! ******************************
  54. ; All these buttons do the same thing. They AppVar their number or letter
  55. ; to our main variable and redisplay it
  56.  
  57.  
  58. ;=======================> The Buttons for the plain numbers
  59.  
  60. xBUTTON 10 25 25 15 1
  61. gadkey 1                       ; Keyboard shortcut
  62. AppVar calc.var 1              ; AppVar the number to "calc.var"
  63. update calc.gc  1 $calc.var   ; and re-display it.
  64.  
  65. xBUTTON 36 25 25 15 2          ; same as above
  66. gadkey  2
  67. AppVar calc.var 2
  68. update calc.gc  1 $calc.var
  69.  
  70. xBUTTON 62 25 25 15 3
  71. gadkey  3
  72. AppVar calc.var 3
  73. update calc.gc  1 $calc.var
  74.  
  75. xBUTTON 10 41 25 15 4
  76. gadkey  4
  77. AppVar calc.var 4
  78. update calc.gc  1 $calc.var
  79.  
  80. xBUTTON 36 41 25 15 5
  81. gadkey  5
  82. AppVar calc.var 5
  83. update calc.gc  1 $calc.var
  84.  
  85. xBUTTON 62 41 25 15 6
  86. gadkey  6
  87. AppVar calc.var 6
  88. update calc.gc  1 $calc.var
  89.  
  90. xBUTTON 10 57 25 15 7
  91. gadkey  7
  92. AppVar calc.var 7
  93. update calc.gc  1 $calc.var
  94.  
  95. xBUTTON 36 57 25 15 8
  96. gadkey  8
  97. AppVar calc.var 8
  98. update calc.gc  1 $calc.var
  99.  
  100. xBUTTON 62 57 25 15 9
  101. gadkey  9
  102. AppVar calc.var 9
  103. update calc.gc  1 $calc.var
  104.  
  105. xBUTTON 10 73 25 15 0
  106. gadkey  0
  107. AppVar calc.var 0
  108. update calc.gc  1 $calc.var
  109.  
  110. xBUTTON 36 73 25 15 .
  111. gadkey  .
  112. AppVar calc.var .
  113. update calc.gc  1 $calc.var
  114.  
  115. xBUTTON 62 73 25 15 <        ; backspace
  116. gadkey #8
  117. cutvar calc.var CUT CHAR -1 ""   ; It will delete the last character of
  118. update calc.gc  1 $calc.var     ; "calc.var" and re-display it
  119.  
  120. ;=========================> The operators
  121.  
  122. xBUTTON 90 25 25 15 /
  123. gadkey  /
  124. AppVar calc.var /
  125. update calc.gc  1 $calc.var
  126.  
  127. xBUTTON 90 41 25 15 *       ; hit twice for square
  128. gadkey  *
  129. AppVar calc.var *
  130. update calc.gc  1 $calc.var
  131.  
  132. xBUTTON 90 57 25 15 -
  133. gadkey  -
  134. AppVar calc.var -
  135. update calc.gc  1 $calc.var
  136.  
  137. xBUTTON 90 73 25 15 +
  138. gadkey  +
  139. AppVar calc.var +
  140. update calc.gc  1 $calc.var
  141.  
  142. ;------------- right most bank
  143.  
  144. xBUTTON 116 25 35 15 (
  145. gadkey  (
  146. AppVar calc.var (
  147. update calc.gc  1 $calc.var
  148.  
  149. xBUTTON 116 41 35 15 )
  150. gadkey  )
  151. AppVar calc.var )
  152. update calc.gc  1 $calc.var
  153.  
  154. xBUTTON 116 57 35 15 CLR       ; Clear
  155. gadkey #127
  156. update calc.gc  1 0
  157. setvar calc.var ""
  158. if $calcmode = BIG                ; update ticker tape
  159.    lvuse calc.gc 2
  160.    LVAdd '** Clear **'
  161. endif
  162.  
  163. xBUTTON 116 73 35 15 =
  164. gadkey #13
  165. gosub calc.gc calculate        ; GoSub the routine which does the calculation
  166.  
  167.  
  168. ;===========================> This is our display panel. - Note it's
  169. ; a xTEXTin type gadget, so we can enter a calculation directly into it.
  170.  
  171. xTEXTIN 10 5 140 18 "" calc.var 0 512
  172. GADID 1
  173. gosub calc.gc calculate        ; GoSub the routine which does the calculation
  174.  
  175.  
  176. ;===================> routine to calculate & display result
  177.  
  178. xROUTINE calculate
  179. lvuse calc.gc 2                        ; use ticker tape lv
  180. if $calc.var > ""                          ; If there is an entry
  181.    if $calcmode = BIG
  182.       LVAdd '$calc.var'
  183.    endif
  184.    cli "rx 'say >env:.result $calc.var'"
  185.    update calc.gc  1  $.result        ; and display the answer EVAL returned
  186.    setvar calc.var $.result           ; We set "calc.var" to the result
  187.    if $calcmode = BIG                 ; update ticker tape
  188.       LVAdd "-> $calc.var"
  189.    endif
  190.    if $calc.var = 0 
  191.       calc.var = ""                   ; and if it's 0, we empty it (looks nicer)
  192.    endif
  193. endif 
  194.  
  195.  
  196. ;***************************** MEMORIES **************************************
  197.  
  198. ; If you look at the following code carefully, you will see that we
  199. ; need a variable within a variable. 
  200. ; We use "membuff" to construct such a variable.
  201.  
  202. ;=======================> Memories display panel
  203.  
  204. xTEXTIN 10 90 140 16 "" $mem 0 30
  205. GadID 5
  206.  
  207. ;=======================> Memories cycler
  208.  
  209. xCycler 10 108 60 15 "" mem
  210. Cstr "M1" .mem1
  211. Cstr "M2" .mem2
  212. Cstr "M3" .mem3
  213. Cstr "M4" .mem4
  214. Cstr "M5" .mem5
  215. setvar membuff "\$$mem"    ; This means set membuff to $ + whatever is in "mem"
  216. update calc.gc 5 $membuff  ; so that it points to the correct variable
  217.  
  218. ;=======================> Memory IN/OUT
  219.  
  220. xButton 70 108 20 15 I          ; These buttons do the usual MEM in/out/+/-
  221. SetVar $mem $calc.var           ; stuff that calculators do.
  222. setvar membuff "\$$mem"
  223. update calc.gc 5 $membuff
  224.  
  225. xButton 90 108 20 15 O
  226. setvar membuff "\$$mem"
  227. AppVar calc.var $membuff
  228. update calc.gc 1 $calc.var
  229.  
  230. xButton 110 108 20 15 +
  231. setvar membuff "\$$mem"
  232. cli "rx 'say >env:$mem $calc.var + $membuff'"
  233. setvar membuff "\$$mem"
  234. update calc.gc 5 $membuff
  235.  
  236. xButton 130 108 20 15 -
  237. setvar membuff "\$$mem"
  238. cli "rx 'say >env:$mem $membuff - $calc.var'"
  239. setvar membuff "\$$mem"
  240. update calc.gc 5 $membuff
  241.  
  242.  
  243. ;***************************** Ticker Tape **********************************
  244.  
  245. ; Here we expand the window to include a listview for the ticker tape
  246. ; This is done on clicking of the Right Mouse Button
  247.  
  248. xOnRMB
  249. if $calcmode = SMALL
  250.    calcmode = BIG
  251.    changegad calc.gc 0 -1 -1 320 128 ""
  252.    setgad calc.gc 2 SHOW
  253. else
  254.    calcmode = SMALL
  255.    lvuse calc.gc 2
  256.    lvclear
  257.    changegad calc.gc 0 -1 -1 160 128 ""
  258.    setgad calc.gc 2 HIDE
  259. endif
  260. redraw calc.gc
  261.  
  262. ;---- This is the listview that will show the results
  263. ;     update main calc pannel according to lv line clicked
  264.  
  265. xListview 155 5 158 123 "" calc.lv "" 10 TXT
  266. gadid 2
  267. cutvar calc.lv copy char 3 calc.3    ; update display to line content
  268. if $calc.3 = '** '            ; clear line
  269.    calc.var = 0
  270. else
  271.    if $calc.3 = '=> '            ; a result
  272.       cutvar calc.lv cut char 3 ""
  273.       calc.var = $calc.lv
  274.    else
  275.       calc.var = $calc.lv        ; a calculation
  276.    endif
  277. endif
  278. update calc.gc 1 $calc.var
  279. if $calc.var = 0
  280.    calc.var = ''
  281. endif
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.